package com.team.engine.util;

import java.util.List;

/**
 * 分页算法，分页信息和查询结果bean
 * 范例：在action类中使用
 * <pre>
 * String page = this.request.getParameter("page");
 * SubPage<TFilegroup> b = this.fileuploadService.getFilegroupAll(page);
 * List<TFilegroup> list = b.getResultList();
 * this.request.setAttribute("result", b);
 * if(list!=null) {
 * 	this.request.setAttribute("totalPage", b.getTotalPage());
 * }
 * return SUCCESS;
 * </pre>
 * @author MengLH
 * @data 2010-8-24
 * @param <T>
 */
public class SubPage<T> {

	/**
	 * 分页开始位置
	 */
	private String begin;
	
	/**
	 * 分页结束位置
	 */
	private String end;
	
	/**
	 * 每页的显示行数
	 */
	private int pageScollSize = 10;
	
	/**
	 * 当前页码
	 */
	private int thisPage;
	
	/**
	 * 条件结果的总行数
	 */
	private Long totalRowNum;

	/**
	 * 总页数
	 */
	private int totalPage;

	private List<T> resultList;
	
	public List<T> getResultList() {
		return resultList;
	}

	public void setResultList(List<T> resultList) {
		this.resultList = resultList;
	}

	/**
	 * 获得总页数
	 * @return
	 */
	public Integer getTotalPage(){
		int i = (int) (totalRowNum / new Long(pageScollSize));
		if((int) (totalRowNum % new Long(pageScollSize)) != 0)
			i += i;
		
		return i;
	}
	
	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}
	
	/**
	 * 获得当前起始行
	 * @return
	 */
	public int getStartRowNum(){
		return thisPage * pageScollSize;
	}
	
	public void setTotalRowNum(Long totalRowNum) {
		this.totalRowNum = totalRowNum;
	}
	
	public Long getTotalRowNum() {
		return totalRowNum;
	}

	public int getPageScollSize() {
		return pageScollSize;
	}

	public void setPageScollSize(int pageScollSize) {
		this.pageScollSize = pageScollSize;
	}

	public int getThisPage() {
		return thisPage;
	}

	public void setThisPage(int thisPage) {
		this.thisPage = thisPage;
	}
	
	public String getBegin() {
		return begin;
	}

	public void setBegin(String begin) {
		this.begin = begin;
	}

	public String getEnd() {
		return end;
	}

	public void setEnd(String end) {
		this.end = end;
	}
}
